package cn.source.system.controller;

import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.core.page.TableDataInfo;
import cn.source.common.enums.BusinessType;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.system.domain.DeyuDialysis;
import cn.source.system.service.IDeyuDialysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 腹透记录Controller
 *
 * @author deyucare.com
 * @date 2025-02-22
 */
@RestController
@RequestMapping("/deyu/dialysis")
public class DeyuDialysisController extends BaseController
{
    @Autowired
    private IDeyuDialysisService deyuDialysisService;

    /**
     * 查询腹透记录列表
     */
    @PreAuthorize("@ss.hasPermi('deyu:dialysis:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeyuDialysis deyuDialysis)
    {
        startPage();
        List<DeyuDialysis> list = deyuDialysisService.selectDeyuDialysisList(deyuDialysis);
        return getDataTable(list);
    }

    /**
     * 获取腹透记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        DeyuDialysis dialysis = new DeyuDialysis();
        dialysis.setId(id);
        return AjaxResult.success(deyuDialysisService.selectDeyuDialysisById(dialysis));
    }

    /**
     * 新增腹透记录
     */
    @PreAuthorize("@ss.hasPermi('deyu:dialysis:add')")
    @Log(title = "腹透记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeyuDialysis deyuDialysis)
    {
        return toAjax(deyuDialysisService.insertDeyuDialysis(deyuDialysis));
    }

    /**
     * 修改腹透记录
     */
    @PreAuthorize("@ss.hasPermi('deyu:dialysis:edit')")
    @Log(title = "腹透记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeyuDialysis deyuDialysis)
    {
        return toAjax(deyuDialysisService.updateDeyuDialysis(deyuDialysis));
    }

    /**
     * 删除腹透记录
     */
    @PreAuthorize("@ss.hasPermi('deyu:dialysis:remove')")
    @Log(title = "腹透记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deyuDialysisService.deleteDeyuDialysisByIds(ids));
    }

    /**
     * 导出腹透记录列表
     */
    @PreAuthorize("@ss.hasPermi('deyu:dialysis:export')")
    @Log(title = "腹透记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeyuDialysis deyuDialysis)
    {
        List<DeyuDialysis> list = deyuDialysisService.selectDeyuDialysisList(deyuDialysis);
        ExcelUtil<DeyuDialysis> util = new ExcelUtil<DeyuDialysis>(DeyuDialysis.class);
        util.exportExcel(response, list, "腹透记录数据");
    }

    /**
     * 查询最近一周风险
     */
    @PreAuthorize("@ss.hasPermi('deyu:dialysis:list')")
    @GetMapping("/getNearlyAWeekOfRisk/{userId}")
    public AjaxResult getNearlyAWeekOfRisk(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(deyuDialysisService.getNearlyAWeekOfRisk(userId));
    }
}
